
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.HashSet;
import java.util.TreeSet;
import java.util.PriorityQueue;

class student2 implements Comparable<student2> //加入implements Comparable做序列化
{

    String name;
    int chi;
    int eng;

    student2(String name, int chi, int eng) {
	this.name = name;
	this.chi = chi;
	this.eng = eng;

    }

    void show() {
	System.out.println("名:" + this.name
		+ "\tchi:" + this.chi
		+ "\teng:" + this.eng);
    }

    public int compareTo(student2 o) //因  Comparable是interface所以須加入public
    {

	return o.chi - this.chi;            //序列化排出大小
    }

}

class add3 {

    public static void main(String args[]) {
		//ArrayList<student2> s=new ArrayList<student2>();
	//LinkedList<student2> s=new LinkedList<student2>();
	//HashSet<student2> s=new HashSet<student2>();
	TreeSet<student2> s = new TreeSet<student2>();         //須定出順序
	//PriorityQueue<student2> s=new PriorityQueue<student2>();    //須定出順序
	s.add(new student2("abc1", 79, 100));
	s.add(new student2("abc1", 78, 100));
	s.add(new student2("abc3", 75, 90));
	s.add(new student2("abc4", 76, 100));

	for (student2 o : s) {
	    o.show();
	}

	/*student2[] s=new student2[3];
	 s[0]=new student2("abc1",78,100);
	 s[1]=new student2("abc2",68,80);
	 s[2]=new student2("abc3",75,90);
	 //s[3]=new student2("abc4",75,100);
	 for(student2 o:s)
	 {
	 o.show();
	 }*/
    }
}
